package com.tth.learn.addproperties.java1;

import org.junit.Test;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @Author tth
 * @Date 2023/1/3 15:07
 */
public class ConstructorReferenceTest {

    /**
     * 空参构造器
     * Supplier<T>中的 T get()
     */
    @Test
    public void test1() {
        //
        Supplier<Person> sup1 = () -> new Person();
        System.out.println(sup1.get());

        System.out.println("*******************************************");

        Supplier<Person> sup2 = Person::new;
        System.out.println(sup2.get());
    }

    /**
     * 含一个参数的构造器
     * Function<T, R>中的R apply(T t)
     */
    @Test
    public void test2() {
        Function<String, Person> fun1 = name -> new Person(name);
        System.out.println(fun1.apply("Tom"));

        System.out.println("*******************************************");

        Function<String, Person> fun2 = Person::new;
        System.out.println(fun2.apply("张三"));
    }

    /**
     * 含2个参数的构造器
     * BiFunction<T, U, R>中的R apply(T t, U u)
     */
    @Test
    public void test3() {
        BiFunction<String, Integer, Person> bi1 = (name, age) -> new Person(name, age);
        System.out.println(bi1.apply("Steven", 18));

        System.out.println("*******************************************");

        BiFunction<String, Integer, Person> bi2 = Person::new;
        System.out.println(bi2.apply("李四", 22));
    }
}
